<template>
  <div class="followUp">
    <div class="btn">
      <el-button type="primary" @click="onSubmit">保存</el-button>
      <el-button @click="onReset">重置</el-button>
    </div>
    <el-table :data="dataList" border>
      <el-table-column prop="type" label="类型" align="center" />
      <el-table-column prop="itemName" label="字段中文名" align="center" />
      <el-table-column prop="value" label="选项默认值" align="center">
        <template slot-scope="scope">
          <el-radio-group v-model="scope.row.value">
            <el-radio
              v-for="item in scope.row.options"
              :key="item.value"
              :label="item.value"
              >{{ item.label }}</el-radio
            >
          </el-radio-group>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script type="text/javascript">
import {
  showCpFollowUpSets,
  saveCpFollowUpSet,
  saveCpFollowUpSets,
} from "@/api/follow-up/chest-pain";
export default {
  name: "",
  data() {
    return {
      dataList: [],
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    // 获取详情数据
    async getData() {
      const result = await showCpFollowUpSets();
      this.dataList = result?.data?.cpFollowUpSets || [];
      this.dataList.map((item) => {
        // item.selectionList =
        //   '[{"label":"是","value":"1"},{"label":"否","value":"0"}]';
        item.options = JSON.parse(item.selectionList);
      });
    },
    async onSubmit() {
      await saveCpFollowUpSets(this.dataList);
      this.$message({
        type: "success",
        message: "保存成功",
      });
    },
    async onReset() {
      this.dataList.map((item) => {
        item.value == item.options[0]?.value;
      });
      await saveCpFollowUpSets(this.dataList);
      this.$message({
        type: "success",
        message: "重置成功",
      });
    },
  },
};
</script>

<style lang='scss' scoped >
.followUp {
  .btn {
    display: flex;
    justify-content: end;
    margin-bottom: 10px;
  }
}
</style>
